package tools;

import java.io.FileOutputStream;
import java.sql.Connection;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.database.QueryDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;

/**
 * Class DBToXML qui permet de convertir certaines tables d'une base de données en fichier XML
 */

public class DBToXML {

  public static void main(String[] args) throws Exception {
    // database connection
    Connection conn = modele.ConnexionBD.getConnection();
    IDatabaseConnection connection = new DatabaseConnection(conn);

     String[] lstTables = {"formateur", "administration", "annee_session", "formation2",
            "maitre_stage", "module", "candidat", "etudiant_session", "etudiant", "retour_sur_module", "retour_sur_etudiant"};

        QueryDataSet queryDataSet = new QueryDataSet(connection);

        for (int i = 0; i < lstTables.length; ++i) {
            queryDataSet.addTable(lstTables[i]);

        }


    FlatXmlDataSet.write(queryDataSet, new FileOutputStream("BD2.xml"));
  }
}
